package webServlets;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ValiImageServlet extends HttpServlet {
    public static String text = null;

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
// 1.接收请求
// 2.调用工具类，生成验证码图片
        VerifyCode vc = new VerifyCode();
// 3.将生成的验证码图片存入response实体中
        vc.drawImage(resp.getOutputStream());
// 4.控制浏览器不要缓存验证码图片
        resp.setHeader("Pragma", "no-cache");
        resp.setHeader("Cache-Control", "no-cache");
//将生成的验证码的文本内容输出到控制台
        text = vc.getCode();
        System.out.println("text=" + text);
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException,IOException {
        doGet(req, resp);
    }
}
